package top.healthylife.jobs;/*
 *@Author GaoZeXi
 *@Created time 2020/4/10 1:08
 *@Description:
 * Step by Step  and Stand on,  You Are The Best Investment!!!
 */

import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;
import top.healthylife.constant.RedisConstant;
import top.healthylife.utils.QiniuyunUtils;

import java.util.Set;

public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg() {
        //根据Redis 中的两个Set集合进行差值计算,获得垃圾图片名字集合
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_ALL_PIC_RESOURCES, RedisConstant.SETMEAL_VALUED_PIC_RESOURCES);
        if(set!=null){
            for (String fileName : set) {
                System.out.println("清理无效图片数据,fileName"+fileName);
//              //删除云上无效图片
                QiniuyunUtils.deleteFileFromQiniu(fileName);
                //
                jedisPool.getResource().srem(RedisConstant.SETMEAL_ALL_PIC_RESOURCES,fileName);
            }
        }

    }
}
